package com.aos.erp.fs.storage;

import com.aos.erp.fs.model.SysFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Calendar;

public interface FileStorageHandler {

    /**
     * 文件存储接口
     *
     * @param sysFile
     * @param file
     * @return 是否保存成功
     */
    boolean save(SysFile sysFile, MultipartFile file, String type);


    /**
     * 判断是否能处理
     *
     * @param sysFile
     * @param file
     * @param type
     * @return
     */
    boolean canHandler(SysFile sysFile, MultipartFile file, String type);

    /**
     * 排序
     *
     * @return
     */
    default int order() {
        return Integer.MAX_VALUE;
    }


    default String getStoragePath(String appId, String bizType) {
        Calendar calendar = Calendar.getInstance();
        String path = appId + File.separator;
        path = bizType + File.separator;
        path = path + calendar.get(Calendar.YEAR) + "" + File.separator;
        path = path + (calendar.get(Calendar.MONTH) + 1) + "" + File.separator;
        path = path + calendar.get(Calendar.DAY_OF_MONTH) + "";
        return path;
    }

}
